{{- /* trim the newline */ -}}
{{- $content := trim (partial "function/dos2unix.html" .Inner) "\n" -}}
{{- $classList := slice -}}
{{- with .Get "class" -}}
  {{- $classList = $classList | append . -}}
{{- end -}}
{{- $tag := .Get "tag" | default "div" -}}
{{- $loop := cond (ne (.Get "group") "") false (.Get "loop") -}}

{{- if .Get "code" -}}
  {{- /* highlight code content without line number */ -}}
  {{- $content = highlight $content (.Get "code") "lineNos=false, noClasses=false" -}}
  {{- /* delete outer label */ -}}
  {{- $content = replaceRE `.*<code[^<>]*>(?s)(.*)</code>.*` "$1" $content -}}
  {{- if .Get "code-link" -}}
    {{- /* parsing code links */ -}}
    {{- $content = replaceRE `(<span[^<>]*>)([^<>]*)\[([^<>]+)\]\(([^<>]+)\)([^<>]*)(</span>)` "$1$2$6<a href=\"$4\">$3</a>$1$5$6" $content -}}
  {{- end -}}
  {{- $classList = $classList | append "highlight" -}}
{{- else -}}
  {{- $content = $content | .Page.RenderString -}}
{{- end -}}

{{- $wrapperAttrs := `class="typeit"` -}}
{{- with (.Get "group" | string) -}}
  {{- $wrapperAttrs = printf `%v data-group="%v"` $wrapperAttrs . -}}
{{- end -}}
{{- with $loop -}}
  {{- $wrapperAttrs = printf `%v data-loop="true"` $wrapperAttrs -}}
{{- end -}}

{{- $innerAttrs := "" -}}
{{- with $classList -}}
  {{- $innerAttrs = printf `class="%v"` (delimit $classList " ") -}}
{{- end -}}

<div {{ $wrapperAttrs | safeHTMLAttr }}>
  {{- printf `<%v %v></%v>` $tag $innerAttrs $tag | safeHTML -}}
  <template><pre>{{ printf "%v" $content | safeHTML }}</pre></template>
</div>
{{- .Page.Store.Set "hasTyped" true -}}
